package com.woniu.springcrud.service.impl;

import com.woniu.springcrud.entity.User;
import com.woniu.springcrud.mapper.UserMapper;
import com.woniu.springcrud.service.UserService;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.apache.tomcat.util.security.MD5Encoder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: 16327
 * @date: 2021/1/18 15:38
 * @description:
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    @Override
    public List<User> findAll() {
        List<User> users = userMapper.selectByExample(null);
        return users;
    }

    @Override
    public int deleteUserById(Integer id) {
        int i = userMapper.deleteByPrimaryKey(id);
        return i;
    }

    @Override
    public int updateUser(User user) {
        user.setPassword(new Md5Hash(user.getPassword(),"aa",1024).toString());
        user.setSalt("aa");
        int i = userMapper.updateByPrimaryKey(user);
        return i;
    }

    @Override
    public int insertUser(User user) {
        user.setPassword(new Md5Hash(user.getPassword(),"aa",1024).toString());
        user.setSalt("aa");
        return userMapper.insert(user);
    }
}
